@@ -13,10 +13,12 @@ RUN apt-get update && \ |
||
| 13 | 13 |
libgdbm-dev libreadline-dev libncurses5-dev libffi-dev \ |
| 14 | 14 |
libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev \ |
| 15 | 15 |
graphviz libgraphviz-dev \ |
| 16 |
- ruby2.1 ruby2.1-dev supervisor && \ |
|
| 16 |
+ ruby2.1 ruby2.1-dev supervisor python-pip && \ |
|
| 17 | 17 |
gem install --no-ri --no-rdoc bundler && \ |
| 18 | 18 |
rm -rf /var/lib/apt/lists/* |
| 19 | 19 |
|
| 20 |
+RUN pip install supervisor-stdout |
|
| 21 |
+ |
|
| 20 | 22 |
ADD scripts/ /scripts |
| 21 | 23 |
RUN chmod 755 /scripts/setup /scripts/init |
| 22 | 24 |
|
@@ -38,9 +38,29 @@ case "${DATABASE_ADAPTER}" in
|
||
| 38 | 38 |
*) echo "Unsupported database adapter. Available adapters are mysql2, and postgres." && exit 1 ;; |
| 39 | 39 |
esac |
| 40 | 40 |
|
| 41 |
-# start supervisord |
|
| 42 |
-/usr/bin/supervisord -c /etc/supervisor/supervisord.conf |
|
| 41 |
+# initialize supervisord config |
|
| 42 |
+ |
|
| 43 |
+cat > /etc/supervisor/conf.d/supervisord.conf <<EOF |
|
| 44 |
+[supervisord] |
|
| 45 |
+nodaemon = true |
|
| 46 |
+user = root |
|
| 47 |
+logfile = /dev/stdout |
|
| 48 |
+loglevel = debug |
|
| 49 |
+ |
|
| 50 |
+[unix_http_server] |
|
| 51 |
+file=/tmp/supervisor.sock ; (the path to the socket file) |
|
| 52 |
+ |
|
| 53 |
+[eventlistener:stdout] |
|
| 54 |
+command = supervisor_stdout |
|
| 55 |
+buffer_size = 100 |
|
| 56 |
+events = PROCESS_LOG |
|
| 57 |
+result_handler = supervisor_stdout:event_handler |
|
| 58 |
+EOF |
|
| 59 |
+ |
|
| 60 |
+# prepare the supervisord bootstrap service script |
|
| 43 | 61 |
|
| 62 |
+cat <<BOOTSTRAP > /tmp/bootstrap.sh |
|
| 63 |
+#!/bin/bash -xe |
|
| 44 | 64 |
# start mysql server if ${DATABASE_HOST} is localhost
|
| 45 | 65 |
if [ "${DATABASE_HOST}" == "localhost" ]; then
|
| 46 | 66 |
if [ "${DATABASE_ADAPTER}" == "postgres" ]; then
|
@@ -57,8 +77,8 @@ command=/usr/bin/mysqld_safe |
||
| 57 | 77 |
user=root |
| 58 | 78 |
autostart=false |
| 59 | 79 |
autorestart=true |
| 60 |
-stdout_logfile=/var/log/supervisor/%(program_name)s.log |
|
| 61 |
-stderr_logfile=/var/log/supervisor/%(program_name)s.log |
|
| 80 |
+stdout_events_enabled=true |
|
| 81 |
+stderr_events_enabled=true |
|
| 62 | 82 |
EOF |
| 63 | 83 |
supervisorctl reload |
| 64 | 84 |
|
@@ -92,7 +112,29 @@ EOF |
||
| 92 | 112 |
echo "GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON \`${DATABASE_NAME}\`.* TO 'root'@'localhost';" | mysql -uroot ${DATABASE_PASSWORD:+-p$DATABASE_PASSWORD}
|
| 93 | 113 |
fi |
| 94 | 114 |
fi |
| 115 |
+supervisorctl start huginn >/dev/null |
|
| 116 |
+BOOTSTRAP |
|
| 117 |
+ |
|
| 118 |
+chmod 755 /tmp/bootstrap.sh |
|
| 119 |
+ |
|
| 120 |
+cat > /etc/supervisor/conf.d/bootstrap.conf <<EOF |
|
| 121 |
+[program:bootstrap] |
|
| 122 |
+command=/tmp/bootstrap.sh |
|
| 123 |
+priority=10 |
|
| 124 |
+directory=/app |
|
| 125 |
+process_name=%(program_name)s |
|
| 126 |
+autostart=true |
|
| 127 |
+autorestart=false |
|
| 128 |
+stdout_events_enabled=true |
|
| 129 |
+stderr_events_enabled=true |
|
| 130 |
+stopsignal=TERM |
|
| 131 |
+exitcodes=0 |
|
| 132 |
+startsecs=0 |
|
| 133 |
+stopwaitsecs=1 |
|
| 134 |
+EOF |
|
| 95 | 135 |
|
| 136 |
+cat <<FOREMAN > /tmp/foreman.sh |
|
| 137 |
+#!/bin/bash |
|
| 96 | 138 |
# Assuming we have a created database, run the migrations and seed it idempotently. |
| 97 | 139 |
[ -z "${DO_NOT_MIGRATE}" ] && sudo -u huginn -EH bundle exec rake db:migrate
|
| 98 | 140 |
[ -z "${DO_NOT_SEED}" ] && sudo -u huginn -EH bundle exec rake db:seed
|
@@ -100,12 +142,30 @@ fi |
||
| 100 | 142 |
[ -n "$INTENTIONALLY_SLEEP" ] && sleep $INTENTIONALLY_SLEEP |
| 101 | 143 |
|
| 102 | 144 |
# Fixup the Procfile and prepare the PORT |
| 103 |
-[ -z "${DO_NOT_RUN_JOBS}" ] && perl -pi -e 's/^jobs:/#jobs:/' /app/Procfile
|
|
| 145 |
+[ -n "${DO_NOT_RUN_JOBS}" ] && perl -pi -e 's/^jobs:/#jobs:/' /app/Procfile
|
|
| 104 | 146 |
perl -pi -e 's/rails server$/rails server -p \$PORT/' /app/Procfile |
| 105 | 147 |
export PORT |
| 106 | 148 |
|
| 107 | 149 |
# Start huginn |
| 108 |
-sudo -u huginn -EH bundle exec foreman start |
|
| 150 |
+exec sudo -u huginn -EH bundle exec foreman start |
|
| 151 |
+FOREMAN |
|
| 152 |
+ |
|
| 153 |
+chmod 755 /tmp/foreman.sh |
|
| 109 | 154 |
|
| 110 |
-# As the ENTRYPOINT script, when this exits the docker container will Exit. |
|
| 111 |
-exit 0 |
|
| 155 |
+cat > /etc/supervisor/conf.d/foreman.conf <<EOF |
|
| 156 |
+[program:rails] |
|
| 157 |
+command=/tmp/foreman.sh |
|
| 158 |
+priority=10 |
|
| 159 |
+directory=/app |
|
| 160 |
+process_name=%(program_name)s |
|
| 161 |
+autostart=false |
|
| 162 |
+autorestart=true |
|
| 163 |
+stdout_events_enabled=true |
|
| 164 |
+stderr_events_enabled=true |
|
| 165 |
+stopsignal=TERM |
|
| 166 |
+startsecs=0 |
|
| 167 |
+stopwaitsecs=1 |
|
| 168 |
+EOF |
|
| 169 |
+ |
|
| 170 |
+# start supervisord |
|
| 171 |
+exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf |
@@ -7,7 +7,7 @@ set -e |
||
| 7 | 7 |
ON_HEROKU=${ON_HEROKU:-true}
|
| 8 | 8 |
|
| 9 | 9 |
# Shallow clone the huginn project repo |
| 10 |
-git clone --depth 1 https://github.com/cantino/huginn /app |
|
| 10 |
+git clone --depth 1 https://github.com/ianblenke/huginn /app |
|
| 11 | 11 |
|
| 12 | 12 |
cd /app |
| 13 | 13 |
|